Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework plugin tickers to prevent drift and spread write ticks #7390

Merged
merged 3 commits into from
May 6, 2020

Conversation

danielnelson
Copy link
Contributor

@danielnelson danielnelson commented Apr 23, 2020

Fix several drift issues when using round_interval and use a rolling ticker for doing the full write flush. In the future I would like to rework the output to only do full flushes after flush_interval seconds has elapsed without a batch write. This will reduce unneeded calls to write but can be done separately.

It is possible that we will want to use the "RollingTicker" for inputs as well, since it would give you the best collection spread. However, making the switch when using jitter requires changing the configuration in order to maintain the same collection pace, so I haven't switched in this pull request.

closes #5937
closes #5335
closes #4232
closes #4652

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@danielnelson danielnelson added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin fix pr to fix corresponding bug area/agent labels Apr 23, 2020
@danielnelson danielnelson added this to the 1.15.0 milestone Apr 23, 2020
@danielnelson danielnelson requested review from ssoroka and reimda April 23, 2020 09:13
Copy link
Contributor

@ssoroka ssoroka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A thing of beauty. Well done.

agent/tick_test.go Show resolved Hide resolved

func TestAlignedTickerJitter(t *testing.T) {
interval := 10 * time.Second
jitter := 5 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go should use the same rand seed every time, so you should be able to test the specific jitter if desired

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to redo internal.RandomDuration to support a custom rand instance first, I'm getting fluctuations as-is even if I reset the Seed when the test starts. Anyway it would be nice to have the tests work if ran concurrently.

Copy link
Contributor

@ssoroka ssoroka Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is that internal.RandomDuration is depending on crypto/rand, which doesn't make a lot of sense. We really don't need cryptographic randomness for setting sleep timers. might want to change this to math/rand and it should start respecting the seed.

agent/tick_test.go Show resolved Hide resolved
printDist(ticker, clock)
}

func printDist(ticker Ticker, clock *clock.Mock) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we check a that the avg wait time is within expected bounds, and that we got the number of ticks expected.

agent/agent.go Show resolved Hide resolved
agent/tick.go Outdated
return
case <-ticker.C:
jitter := internal.RandomDuration(t.jitter)
sleep(ctx, jitter, clock)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't handle returned error. next line pushes to chan even if context done

Copy link
Contributor

@ssoroka ssoroka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm just waiting on the math/rand change.

@danielnelson danielnelson requested a review from ssoroka May 1, 2020 04:47
agent/agent.go Show resolved Hide resolved
@danielnelson danielnelson merged commit fd76c8b into master May 6, 2020
@danielnelson danielnelson deleted the absolute-align-interval branch May 6, 2020 18:59
idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/agent feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin fix pr to fix corresponding bug
Projects
None yet
3 participants